package com.example.test.dialogfactory;

import android.app.Notification;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.os.Build;
import android.util.Log;
import androidx.core.app.NotificationCompat;
import easier.app.x.service.BinderService;

public class MainActivity119ForeService extends BinderService {

    private static final String TAG = "MainActivity119ForeServ";
    private static final String CHANNEL_ID = "ForegroundServiceChannel";

    public void sayHello() {

        System.out.println( "hello foregroundService " + this );
        Log.i( TAG, "sayHello: hello foregroundService" + this );
    }

    public void startFore() {

        createNotificationChannel();
        Notification notification = new NotificationCompat.Builder( this, CHANNEL_ID )
            .setContentTitle( "前台服务标题" )
            .setContentText( "前台服务内容" )
            .setSmallIcon( R.drawable.a5452 )
            .build();

        startForeground( CHANNEL_ID.hashCode(), notification );
    }

    private void createNotificationChannel() {

        if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ) {
            NotificationChannel channel = new NotificationChannel(
                CHANNEL_ID,
                "Foreground Service Channel",
                NotificationManager.IMPORTANCE_DEFAULT
            );

            NotificationManager manager = getSystemService( NotificationManager.class );
            manager.createNotificationChannel( channel );
        }
    }
}